MuMag2022: a software tool for analyzing magnetic field dependent unpolarized small-angle neutron scattering data of bulk ferromagnets

The MATLAB-based software tool MuMag2022 is presented for the analysis of magnetic-field-dependent unpolarized small-angle neutron scattering data of bulk ferromagnets such as elemental nanocrystalline ferromagnets, magnetic nanocomposites or magnetic steels.


Introduction
Magnetic small-angle neutron scattering (SANS) is in many respects different from nonmagnetic nuclear SANS or smallangle X-ray scattering (SAXS). This is mainly related to the following points: (i) the quantity of interest in magnetic SANS is the three-dimensional magnetization vector field of the sample, MðrÞ, while it is the scalar nuclear density NðrÞ that is of relevance in nonmagnetic SANS. Therefore, besides changes in the magnitude of M, spatial variations in the orientation of M are of special importance for magnetic SANS. (ii) The method for obtaining MðrÞ, a continuum micromagnetic variational ansatz aiming to minimize the total magnetic energy of the system, is conceptually different from that used to obtain NðrÞ -mostly concepts based on particle form factors and structure factors. (iii) As a consequence of the quantum-mechanical exchange interaction, magnetization profiles are smoothly varying continuous functions of the position, which entails the absence of sharp (discontinuous) features in the magnetic microstructure. Although models with a smoothly varying NðrÞ have also been developed for nonmagnetic SANS (e.g. Schmidt et al., 1991;Heinemann et al., 2000), the most widespread approach in particle scattering is to fit a certain form-factor model, implying the presence of a sharp interface, to a set of experimental data. These differences have fundamental consequences regarding the scattering behavior; e.g. magnetic SANS on bulk ferromagnets does generally not exhibit an asymptotic q À4 Porod law, but may reveal larger power-law exponents (e.g. Bersweiler et al., 2021). Related to the previous statement is the fact that the correlation function of magnetic systems exhibits a different functional dependency from the density-density autocorrelation function of nonmagnetic particle systems.
A theoretical framework for magnetic SANS has been developed in recent years (Michels, 2021), which allows one to analyze the momentum-transfer and applied-field dependence of the total unpolarized SANS cross section within the approach-to-saturation regime of the macroscopic magnetization. This approach provides information on the magnetic interaction parameters such as the exchange-stiffness constant, and the strength and spatial structure of the magnetic anisotropy and magnetostatic field. The software tool MuMag2022 presented here encodes the relevant expressions and allows for the analysis of (2 azimuthally averaged) magnetic-field-dependent unpolarized SANS data of bulk ferromagnets; examples are elemental nanocrystalline ferromagnets, magnetic nanocomposites or magnetic steels.
The article is organized as follows: Section 2 summarizes, for the two most often employed scattering geometries, the main theoretical expressions for the unpolarized nuclear and magnetic SANS cross section and explains the data analysis procedure. Section 3 provides some details on the operation of the MuMag2022 software and Section 4 presents some selected example cases.

Magnetic SANS theory -unpolarized neutrons
The magnetic-field-dependent SANS of bulk ferromagnets is typically dominated by the spin-misalignment scattering, i.e. the part of the magnetic SANS cross section that is related to the transverse magnetization Fourier coefficients. Since the spin-misalignment SANS is independent of the polarization of the incident neutron beam, half-polarized ('spin-up' and 'spindown') SANSPOL 1 experiments, which additionally provide access to nuclear-magnetic interference terms, do not provide significantly more information regarding spin misalignment than can already be learned from the analysis of the unpolarized scattering. Chiral correlations are also ignored in our treatment. Therefore, the first version of our software package MuMag2022 considers only the case of unpolarized SANS. In the following, we summarize the main equations for the nuclear and magnetic SANS cross section of bulk ferromagnets, focusing on the two most often used scattering geometries which have the externally applied magnetic field either perpendicular or parallel to the incoming beam.

k 0 ? H 0
For the scattering geometry where the applied magnetic field H 0 k e z is perpendicular to the wavevector k 0 k e x of the incoming neutron beam [see Fig. 1(a)], the elastic (unpolarized) SANS cross section dAE=d at scattering vector q can be written as (Michels, 2021) dAE d ðqÞ ¼ 8 3 V b 2 the nuclear scattering length density and of the magnetization MðrÞ ¼ fM x ðrÞ; M y ðrÞ; M z ðrÞg, and represents the angle between H 0 and q ffi qf0; sin ; cos g; the asterisks Ã mark the complex-conjugated quantity.
As shown by , near magnetic saturation, dAE=d can be evaluated by means of micromagnetic theory. In particular, represents the nuclear and magnetic residual SANS cross section, which is measured at complete magnetic saturation (infinite field), and is the spin-misalignment SANS cross section. The magnetic scattering due to transverse spin components, with related  Sketch of the two most often employed scattering geometries in magnetic SANS experiments. (a) k 0 ? H 0 ; (b) k 0 k H 0 . We emphasize that in both geometries the applied-field direction H 0 defines the e z direction of a Cartesian laboratory coordinate system. The momentum transfer or scattering vector q corresponds to the difference between the wavevectors of the incident (k 0 ) and the scattered (k 1 ) neutrons, i.e. q ¼ k 0 À k 1 . Its magnitude for elastic scattering, q ¼ jqj ¼ ð4=Þ sinð Þ, depends on the mean wavelength of the neutrons and on the scattering angle 2 . SANS is usually implemented as elastic scattering (k 0 ¼ k 1 ¼ 2=), and the component of q along the incident neutron beam [i.e. q x in (a) and q z in (b)] is neglected. The angle specifies the orientation of the scattering vector on the two-dimensional detector; is measured between H 0 k e z and q ffi f0; q y ; q z g (a) and between e x and q ffi fq x ; q y ; 0g (b). Note that in many SANS publications the scattering angle is denoted by the symbol 2. However, in order to comply with our previous notation (see e.g. the publications in the reference list), we prefer to denote this quantity by 2 . magnetostatic fields. The micromagnetic SANS theory considers a uniform exchange interaction and a random distribution of the magnetic easy axes, as is appropriate for a statistically isotropic polycrystalline ferromagnet (Michels, 2021). Spatial variations in the magnitude of the saturation magnetization are explicitly taken into account via the function S M (see below). Moreover, in the approach-to-saturation regime it is assumed that j e M M z j 2 ¼ j e M M s j 2 , where e M M s ðqÞ denotes the Fourier transform of the saturation magnetization profile M s ðrÞ.
Regarding the decomposition of the SANS cross section [equation (2)], we emphasize that it is dAE M =d that depends on the magnetic interactions (exchange, anisotropy, magnetostatics), while dAE res =d is determined by the geometry of the underlying grain microstructure (e.g. the particle shape or the particle-size distribution). If in a SANS experiment the approach-to-saturation regime can be reached for a particular magnetic material (as is assumed here), then the residual SANS can be obtained by an analysis of field-dependent data via the extrapolation to infinite field (see Section 2.4). In a sense, for a bulk ferromagnet, the scattering at saturation resembles the topographical background in Kerr-microscopy experiments, which needs to be subtracted in order to access the magnetic domain structure of the sample (McCord & Hubert, 1999).
The anisotropy-field scattering function (in units of cm À1 ) depends on e H H p ðqÞ, which represents the Fourier transform of the spatial structure of the magnetic anisotropy field H p ðrÞ of the sample, whereas the scattering function of the longitudinal magnetization (in units of cm À1 ) provides information on the spatial variation of the saturation magnetization M s ðrÞ; for instance, in a multiphase magnetic nanocomposite, S M / j e M M z j 2 / ðÁMÞ 2 , where ÁM denotes the jump of the magnetization magnitude at internal (particlematrix) interfaces. Note that the volume average of M s ðrÞ equals the macroscopic saturation magnetization M 0 ¼ hM s ðrÞi of the sample, which can be measured with a magnetometer. The corresponding dimensionless micromagnetic response functions can be expressed as (Michels, 2021) and where pðq; is a dimensionless function and represents the angle between H 0 ¼ H 0 e z and q ffi qf0; sin ; cos g. The effective magnetic field depends on the internal magnetic field and on the micromagnetic exchange length of the field the approach-to-saturation regime. The dependence of R H and R M arises essentially as a consequence of the magnetodipolar interaction. Depending on the values of q and H i , a variety of angular anisotropies may be seen on a two-dimensional position-sensitive detector (Michels, 2021). The effective magnetic field H eff [equation (10)] consists of a contribution due to the internal field H i and the exchange field 2Aq 2 =ð 0 M 0 Þ. An increase of H i increases the effective field only at the smallest q values, whereas H eff at larger q is always very large ($10-100 T) and independent of H i (Michels, 2021). The latter statement may be seen as a manifestation of the fact that exchange forces tend to dominate on small length scales (Aharoni, 2000). Since H eff appears predominantly in the denominators of the final expressions for e M M x and e M M y [compare equations (3.68) and (3.69) of Michels (2021)], its role is to suppress the high-q Fourier components of the magnetization, which correspond to sharp real-space fluctuations. On the other hand, long-range magnetization fluctuations, at small q, are effectively suppressed when H i is increased.
By assuming that the functions e N N, e M M z and e H H p depend only on the magnitude q ¼ jqj of the scattering vector, one can perform an azimuthal average of equation (2), i.e. 1=ð2Þ R 2 0 ð. . .Þ d. The resulting expressions for the response functions then read and so that the azimuthally averaged total nuclear and magnetic SANS cross section can be written as For materials exhibiting a uniform saturation magnetization (e.g. single-phase materials), the magnetostatic scattering contribution S M R M [to dAE M =d, compare equation (4)] is expected to be much smaller than the anisotropy-field-related term S H R H [compare e.g. Fig. 23 of Michels (2014)]. We emphasize that the micromagnetic theory behind the MuMag2022 software results in an analytical expression for the two-dimensional SANS cross section as a function of the magnitude q and the orientation of the scattering vector q. These analytical expressions can be azimuthally averaged over the full angular detector range 2 (or any other range) and compared with correspondingly averaged experimental SANS data; in other words, it is not required that the experimental input SANS data are isotropic.

k 0 k H 0
For the scattering geometry where the external magnetic field H 0 k e z is parallel to the incident-beam direction k 0 [see Fig. 1(b)], the total azimuthally averaged SANS cross section can be written as (Michels, 2021) where the residual SANS cross section explicitly reads and the response function is isotropic (i.e. independent), S H ðqÞ is given by equation (5), and we note that in this geometry dAE M =d does not depend on e M M z fluctuations and equals the expression for the single-phase material case (Michels, 2021). In other words, the possible two-phase (particle-matrix-type) nature of the underlying microstructure is (for k 0 k H 0 ) only contained in dAE res =d, and not in dAE M =d.

Mean-square anisotropy and magnetostatic field
Numerical integration of S H ðqÞ and S M ðqÞ over the whole q space, i.e.
yields, respectively, the mean-square anisotropy field hjH p j 2 i and the mean-square longitudinal magnetization fluctuation hjM z j 2 i (Michels, 2021). These quantities are, respectively, defined as and Equation (20) follows from equations (21) and (22) (5) and (6)]. Since experimental data for S H and S M are only available within a finite range of momentum transfers between q min and q max (see Fig. 5 below), one can only obtain rough lower bounds for these quantities. Therefore, the numerical integration of equation (20) is carried out for q min q q max ; q min denotes the first experimental data point, while q max is defined by equation (24) below.
Knowledge of S M / j e M M z j 2 and of the residual SANS cross section dAE res =d [equations (16) and (18)] allows one to obtain the nuclear scattering without using sector-averaging procedures (in unpolarized scattering) or polarization analysis (Honecker et al., 2010).

Neutron data analysis procedure
Equation (15) is linear in both R H and R M , with a priori unknown functions dAE res =d, S H and S M . For given values of the materials parameters A and M 0 , the numerical values of both response functions are known at each value of q and H i . By plotting at a particular q ¼ q ? the values of dAE=d measured at several H i versus R H ðq ? ; H i ; AÞ and R M ðq ? ; H i ; AÞ, one can obtain the values of dAE res =d (intercept) and S H and S M (slopes) at q ¼ q ? by a weighted nonnegative linear least-squares plane fit (i.e. the parameters dAE res =d, S H and S M are assumed to be ! 0). The function 'lsqnonneg' of MATLAB has been used for carrying out these fits. Starting from q ¼ q min , the non-negative least-squares fitting routine is successively performed up to a maximum value of q ¼ q max [see equation (24) below]. Fig. 2 illustrates the data analysis procedure. By treating the exchange-stiffness constant A in the expression for H eff as an adjustable parameter, one can obtain information on this quantity. We emphasize that in order to obtain a best-fit value for A from experimental field-dependent SANS data, it is not necessary that the data are available in absolute units. This is because A only appears in the dimensionless response functions R H and R M , while the dimension of the experimental dAE=d (in cm À1 or in arbitrary units) is absorbed in the other fitting parameters dAE res =d, S H and S M .
As mentioned earlier, the effective magnetic field H eff [equation (10)] is the sum of the internal magnetic field H i and computer programs the exchange field ð2A= 0 M 0 Þq 2 . When H i ( ð2A= 0 M 0 Þq 2 , the effective field and, hence, the magnetic SANS cross section become independent of the externally applied magnetic field / H i . This condition defines a characteristic maximum q value, where H max is the maximum applied magnetic field. For q > $ q max , the reliable separation of the spin-misalignment (S H R H þ S M R M ) and residual scattering (dAE res =d) is difficult (since then one attempts to fit a straight line to a constant), and the micromagnetic analysis should therefore be restricted to q < $ q max . The global fitting procedure consists essentially of many straight-plane fits (one at each q value for q < $ q max ). As the experimental best-fit parameter we take the value of A that minimizes the function where the indices m and n count, respectively, the scattering vectors and applied-field values, L is the number of data points (number of q values times the number of internal fields), m;n is the uncertainty in the experimental SANS cross section dAE exp m;n =d ¼ dAE exp =dðq m ; H i;n Þ, and dAE sim m;n =d ¼ dAE sim =dðq m ; H i;n Þ denotes the fit to equation (15) or (17).

Description of the software
The least-squares fitting routine has been written in MATLAB code and implemented into a Windows-and macOS-compatible standalone executable file using the MATLAB app designer. The user has to provide the following data and take the following points into account: (i) The total (nuclear and magnetic) unpolarized SANS cross section dAE=d measured at several applied magnetic fields within the approach-to-saturation regime (2 azimuthally averaged data). Data format: three columns with q in nm À1 , dAE=d in cm À1 and the uncertainty in dAE=d in cm À1 . The input data files must be of the .csv, .dat or .txt type and must have the name structure that is explained in Fig. 3.
(ii) If the dAE=d data are not available in absolute units, then the mean-square magnetic anisotropy field hjH p j 2 i and magnetostatic field hjM z j 2 i [equations (20) Explanation of the input data filename format. The specified numerical values for the applied magnetic fields H 0 , saturation magnetization M 0 and demagnetizing fields H d are automatically taken over by the MuMag2022 software for the data analysis.

Figure 2
Illustration of the neutron data analysis procedure according to equation (15). The total dAE=d (solid circles) of the the iron-based alloy Nanoperm is plotted at q ? = 0.114 nm À1 versus the response functions R H and R M for A = 4.7 pJ m À1 and experimental field values (in mT) of 1270, 312, 103, 61, 42, 33. The plane represents a fit to equation (15). The intercept of the plane with the dAE=d axis provides the residual SANS cross section dAE res =d, while S H and S M are obtained from the slopes of the plane (slopes of the thick black and red lines). In other words, at each experimental q ? , for given materials parameters A and M 0 , and for the experimental field values H i , the total experimental SANS signals at H i are fitted to a function that is of the mathematical form f ðx; yÞ ¼ a þ bx þ cy, where a ¼ dAE res =d, b ¼ S H and c ¼ S M are the fit parameters at q ¼ q ? and x ¼ R H ðq ? ; H i Þ and y ¼ R M ðq ? ; H i Þ are the independent variables. The procedure is carried out for q ¼ q ? values between q min and q max , and then repeated for many different physically plausible A values to determine the best-fit value, A bf , via equation (25). Image taken from Michels (2021), reproduced by permission of Oxford University Press.
(v) The values of the demagnetizing fields 0 H d ¼ 0 N d MðH 0 Þ (in mT) [see point (i) above]. Note that in equation (11) the demagnetizing field was specified as N d M 0 with M 0 the saturation magnetization. The user may, however, take a different value of the demagnetizing field at each value of the externally applied magnetic field H 0 with corresponding magnetization value MðH 0 Þ. The demagnetizing factor N d can be calculated using e.g. the well known formulas for the general ellipsoid by Osborn (1945) or for rectangular prisms by Aharoni (1998).
(vi) The data analysis should be restricted to internal magnetic fields H i within the approach-to-saturation regime. This information can be taken from an experimental magnetization curve MðH i Þ, which also allows for the determination of M 0 . We suggest defining 'approach-to-saturation' for H i values for which the reduced magnetization is M=M 0 > $ 90%.
(vii) An estimate for q max using equation (24). Typical A values are of the order of 10 pJ m À1 (1 pJ m À1 = 10 À12 J m À1 ). The data analysis should be restricted to q < $ q max .
(viii) The following output files are generated (in .csv format). For the perpendicular scattering geometry (k 0 ? H 0 ): best-fit results (using A bf ) for the discrete functions ðdAE res =dÞðqÞ, S H ðqÞ, S M ðqÞ, For the parallel scattering geometry (k 0 k H 0 ): best-fit results (using A bf ) for the discrete functions ðdAE res =dÞðqÞ, S H ðqÞ, R H ðqÞ, ðdAE M =dÞðq; H i Þ = S H ðqÞR H ðq; H i Þ and ðdAE=dÞðq; H i Þ = ðdAE res =dÞðqÞ þ ðdAE M =dÞðq; H i Þ. Data format: three columns with q in nm À1 , the respective quantity in cm À1 (if the input data are in absolute units) and the uncertainty in the respective quantity in cm À1 . Note that R H;M are dimensionless, while dAE res =d and S H;M may be in cm À1 . Moreover, for each scattering geometry, we specify the data set 2 ðAÞ [equation (25)], the best-fit value for the exchange-stiffness constant A bf AE A (in pJ m À1 ) [equation (26)], the root-mean-square anisotropy field 0 ðhjH p j 2 iÞ 1=2 (in mT) and the root-meansquare magnetostatic field 0 ðhjM z j 2 iÞ 1=2 (in mT, only for k 0 ? H 0 ). The provided data give the user the possibility to generate their own graphical representations.

Example cases
The following example data on the two-phase iron-based alloy Nanoperm are taken from the work of , and the data on the Nd-Fe-B nanocomposite are those of Bick et al. (2013). Further examples in the literature where this type of SANS data analysis has been employed can be found in the work of Bersweiler et al. (2022) on another type of Nanoperm sample, and Weissmü ller et al. (2001) and Michels et al. (2003) on nanocrystalline cobalt and nickel. Fig. 4 displays the user interface of the MuMag2022 software, which is structured into five panels: (i) The top panel controls import and graphical representation of the experimental SANS data.
(ii) For the selected scattering geometry (k 0 ? H 0 or k 0 k H 0 ), minimum applied field H min 0 and maximum scattering vector q max , the 'SimpleFit' tool determines the best-fit value A bf for the exchange-stiffness constant. (iii) The 'SweepFit' tool allows one to analyze the convergence of the fitting routine depending on the q max and H min 0 values. (iv) In case the demagnetizing field of the sample is unknown, the 'DemagFit' tool allows for the estimation of this quantity by additionally varying H d in the 2 function [equation (25)]. The obtained best-fit values for A and H d have then to be used in the 'SimpleFit' tool to generate the final fit results for S H , S M and dAE res =d. (v) Finally, by specifying the scattering geometry, materials parameters, applied fields and q range, the MuMag2022 software allows for the generation of synthetic data. We refer to the MuMag2022-Toolbox: User Guide for further details (https://files. uni.lu/mumag/MuMag2022_UserGuide. pdf).
Figs. 5, 6, 7 have been exported from the MuMag2022 software and show, respectively, the experimental field- The user interface of the MuMag2022 software. dependent input data, the results of the data analysis, and the comparison between the experimental data and the fit based on the micromagnetic theory. Note that in Figs. 5 and 7 the values of the applied magnetic fields H 0 are displayed in the legends, while the internal magnetic fields H i (using the values for H 0 and H d specified in the input data files) have been used for internal computations. The best-fit value for the exchangestiffness constant of Nanoperm, A bf = 4.7 Â 10 À12 J m À1 , is found from the minimum of the 2 function in Fig. 6(a), while the q dependence of dAE res =d, S H and S M is featured in Figs. 6(b)-(d), respectively. The results for the average anisotropy ($ 4 mT) and magnetostatic ($ 49 mT) fields [Figs. 6(c) and 6(d), respectively] demonstrate that the strongest perturbations in the spin structure are related to the jumps in the saturation magnetization at internal particlematrix interfaces, in agreement with the two-phase microstructure of the material.
The MuMag2022 software also allows for treating the demagnetizing field H d [in the expression for H i , compare equation (11) Fig. 8 shows the output of the 'DemagFit' tool for the case of an Nd-Fe-B nanocomposite measured in the parallel scattering geometry (k 0 k H 0 ).
The micromagnetic SANS theory on which MuMag2022 is based assumes a statistically isotropic ferromagnetic material with random nanoscale variations in the magnitude and orientation of the magnetic anisotropy field as well as nanoscale spatial variations in the saturation magnetization. Recently, an extended SANS theory which takes into account a global uniaxial anisotropy (magnetic texture) has been developed (Zaporozhets et al., 2022).   Comparison between experiment and theory. Data points: experimental data for the total unpolarized SANS cross section dAE=d of the twophase iron-based alloy Nanoperm at a series of applied magnetic fields within the approach-to-saturation regime (see legend) (log-log scale) (k 0 ? H 0 ). Solid lines: fit using the micromagnetic SANS theory [equation (15)] with the best-fit value of A bf = 4.7 Â 10 À12 J m À1 . The analysis has been restricted to fields 0 H 0 > $ 30 mT and to momentum transfers q q max = 0.2 nm À1 . Note that the fit does not represent a 'continuous' fit of dAE=d in the conventional sense, but rather the pointby-point reconstruction of the theoretical cross sections based on the experimental data. Data taken from .

Figure 5
Total unpolarized experimental SANS cross section dAE=d of the twophase iron-based alloy Nanoperm at a series of applied magnetic fields (see legend) (log-log scale) (k 0 ? H 0 ). Lines are a guide for the eyes. Data taken from . equations for the SANS cross sections will be implemented in a future version of MuMag2022.

Conclusion
The MATLAB-based software tool MuMag2022 allows for the analysis of magnetic-field-dependent small-angle neutron scattering (SANS) data of bulk ferromagnets. Examples of such systems are elemental nanocrystalline ferromagnets, magnetic nanocomposites and magnetic steels. The software is based on the micromagnetic theory for the magnetic SANS cross section, and analyzes unpolarized total (nuclear and magnetic) SANS data within the approach-to-saturation regime of the macroscopic magnetization. The main features of MuMag2022 are the estimation of the exchange-stiffness constant, and of the strength and spatial structure of the magnetic anisotropy field and the magnetostatic field due to longitudinal magnetization fluctuations. MuMag2022 comes with a user-friendly interface and is available along with the example data as a standalone executable for Windows operating systems. It can be downloaded at https://mumag.uni.lu. Additionally, we provide a MuMag2022-Toolbox: User Guide that should enable the operation of the software.